package cn.chiship.framework.upms.biz.user.controller;


import cn.chiship.framework.upms.biz.user.entity.UpmsUserPermissionExample;
import cn.chiship.sdk.core.annotation.Authorization;
import cn.chiship.sdk.framework.base.BaseController;
import cn.chiship.sdk.framework.base.BaseService;
import cn.chiship.framework.common.annotation.SystemOptionAnnotation;
import cn.chiship.sdk.core.base.BaseResult;
import cn.chiship.framework.common.enums.BusinessTypeEnum;
import cn.chiship.framework.upms.biz.user.entity.UpmsUserPermission;

import cn.chiship.framework.upms.biz.user.service.UpmsUserPermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * controller
 *
 * @author lijian
 * @date 2020/4/29
 */
@RestController
@Authorization
@RequestMapping("/userPermission")
@Api(tags = "用户权限关联控制器")
public class UpmsUserPermissionController extends BaseController<UpmsUserPermission, UpmsUserPermissionExample> {

    @Resource
    private UpmsUserPermissionService upmsUserPermissionService;

    @Override
    public BaseService getService() {
        return upmsUserPermissionService;
    }

    @ApiOperation(value = "获取指定用户下的权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户", required = true, dataTypeClass = String.class, paramType = "query"),
    })
    @GetMapping(value = "getPermissionByUserId")
    public ResponseEntity<BaseResult> getPermissionByUserId(@RequestParam("userId") String userId) {
        return super.responseEntity(upmsUserPermissionService.getPermissionByUserId(userId));
    }

    @SystemOptionAnnotation(describe = "保存分配的权限", option = BusinessTypeEnum.SYSTEM_OPTION_SAVE)
    @ApiOperation(value = "保存分配的权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户主键", required = true, dataTypeClass = String.class, paramType = "path"),
    })
    @PostMapping(value = "userPermissionSave/{userId}")
    public ResponseEntity<BaseResult> userPermissionSave(@PathVariable("userId") String userId, @RequestBody @Valid List<String> permissionIdList) {
        return super.responseEntity(upmsUserPermissionService.userPermissionSave(userId, permissionIdList));
    }

    @SystemOptionAnnotation(describe = "删除分配的权限", option = BusinessTypeEnum.SYSTEM_OPTION_REMOVE)
    @ApiOperation(value = "删除分配的权限", notes = "删除分配的权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户主键", required = true, dataTypeClass = String.class, paramType = "path"),
    })
    @PostMapping(value = "userPermissionRemove/{userId}")
    public ResponseEntity<BaseResult> userPermissionRemove(@PathVariable("userId") String userId, @RequestBody @Valid List<String> permissionIdList) {
        return super.responseEntity(upmsUserPermissionService.userPermissionRemove(userId, permissionIdList));
    }


}
